const Date_utils = {
  Date_format: (d) => {
    // 年月日 时分秒
    const newDate =
      d.getFullYear() +
      "-" +
      (d.getMonth() + 1) +
      "-" +
      d.getDate() +
      "" +
      d.getHours() +
      ":" +
      d.getMinutes() +
      ":" +
      d.getSeconds();
    return newDate;
  },

  Date_specific: (d) => {
    // 年月日
    if(d && typeof d === 'object'){
      
      const date = d.getFullYear() +
      "-" +
      (d.getMonth() + 1 > 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1)) +
      "-" +
      (d.getDate() < 10 ? "0" + d.getDate() : d.getDate()) 
      console.log(date);
      return  date
    }else{

      return d;
    }
   
   
  },
  toChineseNumber:(num)=>{
      const strs = num.toString().replace(/(?=(\d{4})+$)/g, ",").split(",").filter(Boolean);
    
      const chinese = ['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']
      const unit = ['','拾','佰','仟']
      //处理四位数
      function _transform(numStr){
          let result = '';
          for (let i = 0; i < numStr.length; i++) {
              const digit = chinese[numStr[i]];
              const c = unit[numStr.length - 1 - i];
              if(digit === '零'){
                  if(result[result.length-1] !== chinese[0]){
                      result += digit;
                  }
              }else{
                  result += digit + c;
              }
          }
          //去除末尾的零
          if(result[result.length-1] === chinese[0]){
              result = result.slice(0, -1);
          }
          return result;
          //console.log(result);
      }
      let res = "";
      const bigUnit = ['','万','亿'];
      for (let i = 0; i < strs.length; i++) {
          const part = strs[i];
          //处理中间四位都是零的情况
          res += _transform(part) ? _transform(part) + bigUnit[strs.length - i - 1] : _transform(part);
      }
      console.log(res);
      console.log(strs);
      return res
    }
    // toChineseNumber(402000000340);
    
    
  }

export default Date_utils;
